package com.lxmes.hr.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.lxmes.hr.domain.NcOriginalAttend;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.lxmes.common.annotation.Log;
import com.lxmes.common.core.controller.BaseController;
import com.lxmes.common.core.domain.AjaxResult;
import com.lxmes.common.enums.BusinessType;
import com.lxmes.hr.domain.NcAttendSummary;
import com.lxmes.hr.service.INcAttendSummaryService;
import com.lxmes.common.utils.poi.ExcelUtil;
import com.lxmes.common.core.page.TableDataInfo;
import org.springframework.web.multipart.MultipartFile;

/**
 * 考勤汇总Controller
 *
 * @author ruoyi
 * @date 2022-11-25
 */
@RestController
@RequestMapping("/hr/attendSummary")
public class NcAttendSummaryController extends BaseController
{
    @Autowired
    private INcAttendSummaryService ncAttendSummaryService;

    /**
     * 查询考勤汇总列表
     */
    @PreAuthorize("@ss.hasPermi('hr:attendSummary:list')")
    @GetMapping("/list")
    public TableDataInfo list(NcAttendSummary ncAttendSummary)
    {
        startPage();
        List<NcAttendSummary> list = ncAttendSummaryService.selectNcAttendSummaryList(ncAttendSummary);
        return getDataTable(list);
    }

    /**
     * 导出考勤汇总列表
     */
    @PreAuthorize("@ss.hasPermi('hr:attendSummary:export')")
    @Log(title = "考勤汇总", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, NcAttendSummary ncAttendSummary)
    {
        List<NcAttendSummary> list = ncAttendSummaryService.selectNcAttendSummaryList(ncAttendSummary);
        ExcelUtil<NcAttendSummary> util = new ExcelUtil<NcAttendSummary>(NcAttendSummary.class);
        util.exportExcel(response, list, "考勤汇总数据");
    }

    /**
     * 获取考勤汇总详细信息
     */
    @PreAuthorize("@ss.hasPermi('hr:attendSummary:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(ncAttendSummaryService.selectNcAttendSummaryById(id));
    }
    /**
     * 获取考勤汇总详细信息
     */
    @PreAuthorize("@ss.hasPermi('hr:attendSummary:query')")
    @GetMapping(value = "/summaryAttend/{type}")
    public AjaxResult summaryAttend(@PathVariable("type") String type)
    {
        return toAjax(ncAttendSummaryService.summaryAttend(type));

    }

    /**
     * 新增考勤汇总
     */
    @PreAuthorize("@ss.hasPermi('hr:attendSummary:add')")
    @Log(title = "考勤汇总", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody NcAttendSummary ncAttendSummary)
    {
        return toAjax(ncAttendSummaryService.insertNcAttendSummary(ncAttendSummary));
    }

    /**
     * 修改考勤汇总
     */
    @PreAuthorize("@ss.hasPermi('hr:attendSummary:edit')")
    @Log(title = "考勤汇总", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody NcAttendSummary ncAttendSummary)
    {
        return toAjax(ncAttendSummaryService.updateNcAttendSummary(ncAttendSummary));
    }

    /**
     * 删除考勤汇总
     */
    @PreAuthorize("@ss.hasPermi('hr:attendSummary:remove')")
    @Log(title = "考勤汇总", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(ncAttendSummaryService.deleteNcAttendSummaryByIds(ids));
    }

    @Log(title = "考勤汇总", businessType = BusinessType.IMPORT)
    @PostMapping("/importData")
    public AjaxResult importData(MultipartFile file, boolean updateSupport) throws Exception
    {
        ExcelUtil<NcAttendSummary> util = new ExcelUtil<>(NcAttendSummary.class);
        List<NcAttendSummary> userList = util.importExcel(file.getInputStream());
        String operName = getUsername();
        String message = ncAttendSummaryService.imporIteminfo(userList, updateSupport, operName);
        return AjaxResult.success(message);
    }

    @PostMapping("/importTemplate")
    public void importTemplate(HttpServletResponse response)
    {
        ExcelUtil<NcAttendSummary> util = new ExcelUtil<>(NcAttendSummary.class);
        util.importTemplateExcel(response, "原始考勤表数据");
    }
}
